package cn.acmenms.manager.redis;

import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName: RedisTemplateManager
 * @Description: redisTemplate管理工具
 * @author: 神奇的鸭鸭
 * @Date: 2018/2/8 15:49
 */
public class RedisTemplateManager implements RedisManager {

    @Resource
    private RedisTemplate<Object, Object> redisTemplate;

    @Override
    public String get(String key) {
        return (String) redisTemplate.opsForValue().get(key);
    }

    @Override
    public void setForTimeMIN(String key, String value, long time) {
        redisTemplate.opsForValue().set(key, value, time, TimeUnit.MINUTES);
    }

    @Override
    public Long increment(String key, long number) {
        return redisTemplate.opsForValue().increment(key, number);
    }

    @Override
    public boolean expire(String key, long time, TimeUnit type) {
        Boolean result = redisTemplate.boundValueOps(key).expire(time, type);
        if(result != null) return result;
        return false;
    }

    @Override
    public boolean delete(String key) {
        Boolean result = redisTemplate.delete(key);
        if(result != null) return result;
        return false;
    }
}